package com.itheima.d2_reflect;

import java.lang.reflect.Member;
import java.lang.reflect.Method;

public class Test3Method {
    public static void main(String[] args) throws Exception {
        Class c=Cat.class;

        Method[] methods=c.getDeclaredMethods();
        for(Method method:methods){
            System.out.println(method.getName()+"--->"+method.getParameterCount()+"--->"+method.getReturnType());
        }

        Method run= c.getDeclaredMethod("run");
        System.out.println(run.getName()+"--->"+run.getParameterCount()+"--->"+run.getReturnType());

        Method eat=c.getDeclaredMethod("eat",String.class);
        System.out.println(eat.getName()+"--->"+eat.getParameterCount()+"--->"+eat.getReturnType());


        Cat cat=new Cat();
        run.setAccessible(true);
        Object obj=run.invoke(cat);
        System.out.println(obj);

        eat.setAccessible(true);
        String rs=(String)eat.invoke(cat,"猫粮");
        System.out.println(rs);
    }
}
